#include "stdafx.h"
#include "GuiUtil.h"

using namespace mgui;

bool mgui::pointInRect(const Point & p, const Rect & rect)
{
	return
		p.X >= rect.X &&
		p.X <= rect.X + rect.Width &&
		p.Y >= rect.Y &&
		p.Y <= rect.Y + rect.Height;
}

mgui::KeyEvent mgui::convert_WM_CHAR_ToKeyEvent( WPARAM wParam, LPARAM lParam )
{
	KeyEvent event;
	switch (wParam)
	{
	case 0x08:
		event.PressedKey = KeyEvent::KEY_BACKSPACE;
		break;
	case 0x0A:
		event.PressedKey = KeyEvent::KEY_ENTER;
		break;
	case 0x1B:
		event.PressedKey = KeyEvent::KEY_ESCAPE;
		break;
	case 0x09:
		event.PressedKey = KeyEvent::KEY_TAB;
		break;
	case 0x0D:
		event.PressedKey = KeyEvent::KEY_CR;
		break;
	default:
		event.PressedKey = KeyEvent::KEY_CHAR;
		event.Char = (TCHAR)wParam;
		break;
	}
	return event;
}

mgui::KeyEvent mgui::convert_WM_KEYDOWN_ToKeyEvent( WPARAM wParam, LPARAM lParam )
{
	KeyEvent event;
	switch (wParam)
	{
	case VK_LEFT:
		event.PressedKey = KeyEvent::KEY_LEFT;
		break;
	case VK_RIGHT:
		event.PressedKey = KeyEvent::KEY_RIGHT;
		break;
	case VK_UP:
		event.PressedKey = KeyEvent::KEY_UP;
		break;
	case VK_DOWN:
		event.PressedKey = KeyEvent::KEY_DOWN;
		break;
	case VK_SPACE:
		event.PressedKey = KeyEvent::KEY_SPACE;
		break;
	case VK_SHIFT:
		event.PressedKey = KeyEvent::KEY_SHIFT;
		break;
	case VK_RETURN:
		event.PressedKey = KeyEvent::KEY_ENTER;
		break;
	default:
		event.PressedKey = KeyEvent::KEY_UNKOWN;
		break;
	}
	return event;
}
